﻿using System.Data;
using System.ServiceModel;
using System.ServiceModel.Web;
using UFIDA.U9.WSS.CommonService.Models;
using UFIDA.U9.WSS.ProxyService.Models;

namespace UFIDA.U9.WSS.CommonService.Interfaces
{
    /// <summary>
    ///     通用服务
    /// </summary>
    [ServiceContract]
    internal interface ICommonService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<bool> TestConnection();

        #region 实体查询

        /// <summary>
        ///     查询实体
        /// </summary>
        /// <param name="queryCond">查询条件</param>
        /// <param name="pageParamter">分页参数</param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<QueryResult<DataTable>> QueryEntity(EntityQueryCond queryCond, PageParamter pageParamter);

        /// <summary>
        ///     通过OQL查询
        /// </summary>
        /// <param name="oql"></param>
        /// <param name="pageParamter"></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<QueryResult<DataTable>> QueryEntityByOQL(string oql, PageParamter pageParamter);

        /// <summary>
        ///     获取实体数量
        /// </summary>
        /// <param name="entityFullName"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<long> GetEntityCount(string entityFullName, string whereClause);

        /// <summary>
        ///     实体是否存在
        /// </summary>
        /// <param name="entityFullName"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<bool> EntityExists(string entityFullName, string whereClause);

        #endregion

        #region SQL查询

        /// <summary>
        ///     通过OQL查询实体
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pageParamter"></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<QueryResult<DataTable>> QueryBySQL(string sql, PageParamter pageParamter);

        /// <summary>
        ///     获取记录数量
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ReturnMessage<long> GetRecordCountBySQL(string sql);

        #endregion
    }
}